home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / ListMan.p < prev    next >
Encoding:
Text File  |  1991-05-21  |  2.5 KB  |  117 lines  |  [TEXT/PJMM]

  1. unit ListMan;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Globals, Types, Utilities, Fonts;
  7.  
  8.     procedure CreateListMan (var lh: listHandle; var rView: rect; proc: integer; wp: windowPtr);
  9.     procedure DestroyListMan (var lh: listHandle);
  10.     procedure UpdateListMan (lh: listHandle);
  11.     procedure AddListMan (lh: listHandle; s: str255);
  12.     function GetListManLength (lh: listHandle): integer;
  13.     function HasSelection (lh: listHandle): boolean;
  14.     procedure SetSelectList (lh: listHandle; sel: boolean);
  15.     procedure SetProcID (id: integer; p: procPtr);
  16.  
  17. implementation
  18.  
  19.     procedure CreateListMan (var lh: listHandle; var rView: rect; proc: integer; wp: windowPtr);
  20.         var
  21.             nrows: integer;
  22.             dataBounds: rect;
  23.             cSize: point;
  24.     begin
  25.         GetListFontInfo(rView, nrows);
  26.         SetRect(dataBounds, 0, 0, 1, 0);
  27.         SetPt(cSize, 0, 0);
  28.         lh := LNew(rView, dataBounds, cSize, proc, wp, true, false, false, true);
  29.     end;
  30.  
  31.     procedure DestroyListMan (var lh: listHandle);
  32.     begin
  33.         LDispose(lh);
  34.         lh := nil;
  35.     end;
  36.  
  37.     procedure UpdateListMan (lh: listHandle);
  38.         var
  39.             r: rect;
  40.     begin
  41.         r := lh^^.rView;
  42.         EraseRect(r);
  43.         InsetRect(r, -1, -1);
  44.         FrameRect(r);
  45.         LUpdate(lh^^.port^.visRgn, lh);
  46.         ValidRect(r);
  47.     end;
  48.  
  49.     procedure AddListMan (lh: listHandle; s: str255);
  50.         var
  51.             r: integer;
  52.             pt: point;
  53.             width: integer;
  54.     begin
  55.         with lh^^, rView do
  56.             width := right - left - 2 * indent.h;
  57.         DotDotDot(s, width);
  58.         r := LAddRow(1, $7FFF, lh);
  59.         pt.h := 0;
  60.         pt.v := r;
  61.         LSetCell(ptr(longInt(@s) + 1), length(s), pt, lh);
  62.     end;
  63.  
  64.     function GetListManLength (lh: listHandle): integer;
  65.     begin
  66.         GetListManLength := lh^^.dataBounds.bottom;
  67.     end;
  68.  
  69.     function HasSelection (lh: listHandle): boolean;
  70.         var
  71.             pt: point;
  72.     begin
  73.         pt.h := 0;
  74.         pt.v := 0;
  75.         HasSelection := LGetSelect(true, pt, lh);
  76.     end;
  77.  
  78.     procedure SetSelectList (lh: listHandle; sel: boolean);
  79.         var
  80.             r: integer;
  81.             pt: point;
  82.     begin
  83.         pt.h := 0;
  84.         for r := 0 to lh^^.dataBounds.bottom do begin
  85.             pt.v := r;
  86.             LSetSelect(sel, pt, lh);
  87.         end;
  88.     end;
  89.  
  90.     procedure SetProcID (id: integer; p: procPtr);
  91.         type
  92.             jmpRec = record
  93.                     jmp: integer;
  94.                     address: procPtr;
  95.                 end;
  96.             jmpPtr = ^jmpRec;
  97.             jmpHandle = ^jmpPtr;
  98.         var
  99.             jmph: jmpHandle;
  100.     begin
  101.         jmph := jmpHandle(GetResource('LDEF', id));
  102.         if jmph = nil then begin
  103.             jmph := jmpHandle(NewHandle(sizeof(jmpRec)));
  104.             AddResource(handle(jmph), 'LDEF', id, 'MadeUp LDEF');
  105.         end;
  106.         if GetHandleSize(handle(jmph)) <> sizeof(jmpRec) then begin
  107.             SysBeep(1);
  108.             Debugger;
  109.             ExitToShell;
  110.         end;
  111.         HLock(handle(jmph));
  112.         HNoPurge(handle(jmph));
  113.         jmph^^.jmp := $4EF9;
  114.         jmph^^.address := p;
  115.     end;
  116.  
  117. end.